package com.hainatong.mvvmbase.http;

public class ApiBuildFactory
{
    private static ApiBuildFactory instance;
    private Object gankHttps;
    private Object doubanHttps;

    public static ApiBuildFactory getInstance()
    {
        if (instance == null)
        {
            synchronized (ApiBuildFactory.class)
            {
                if (instance == null)
                {
                    instance = new ApiBuildFactory();
                }
            }
        }
        return instance;
    }

    public <T> T create(Class<T> a, String type)
    {
        switch (type)
        {
            case RetrofitHelper.API_GANKIO:
                if (gankHttps == null) {
                    synchronized (ApiBuildFactory.class) {
                        if (gankHttps == null) {
                            gankHttps = RetrofitHelper.getInstance().getBuilder(type).build().create(a);
                        }
                    }
                }
                return (T) gankHttps;
            case RetrofitHelper.API_DOUBAN:
                if (doubanHttps == null) {
                    synchronized (ApiBuildFactory.class) {
                        if (doubanHttps == null) {
                            doubanHttps = RetrofitHelper.getInstance().getBuilder(type).build().create(a);
                        }
                    }
                }
                return (T) doubanHttps;
            default:
                if (gankHttps == null) {
                    synchronized (ApiBuildFactory.class) {
                        if (gankHttps == null) {
                            gankHttps = RetrofitHelper.getInstance().getBuilder(type).build().create(a);
                        }
                    }
                }
                return (T) gankHttps;
        }
    }

}
